#include "DDefectInfo.h"
using namespace std;


/*****************************************************************
 *
 *
 *
 *****************************************************************/
DDefectInfo::DDefectInfo()
{

}


/*****************************************************************
 *
 *
 *
 *****************************************************************/
DDefectInfo::DDefectInfo( const DDefectInfo& defInfo )
{
	m_stepID    = defInfo.m_stepID;
	m_testNo    = defInfo.m_testNo;
	m_ID        = defInfo.m_ID;
	m_size      = defInfo.m_size;
	m_stepOrder = defInfo.m_stepOrder;
	m_lgKey     = defInfo.m_lgKey;
}

/*****************************************************************
 *
 *
 *
 *****************************************************************/
DDefectInfo::DDefectInfo( std::string stepID, int testNo, long ID, 
                          double size, int stepOrder, int lgKey )
{
	m_stepID    = stepID;
	m_testNo    = testNo;
	m_ID        = ID;
	m_size      = size;
	m_stepOrder = stepOrder;	
	m_lgKey     = lgKey;
}
 
 
/*****************************************************************
 *
 *
 *
 *****************************************************************/ 
DDefectInfo::DDefectInfo( std::string str )
{
  
  int pos = 1;
  for(
      char *tok = strtok((char *) str.c_str(), ";" );
      tok != NULL;
      tok = strtok(NULL, ";" ), pos++ ){
		switch( pos  ) {
			case 1:	
				m_stepID = tok;
				break;
			case 2:
				m_testNo = atoi(tok);
				break;
			case 3:
				m_ID = atol(tok);
				break;
			case 4:
				m_size = atof(tok);
				break;
			case 5:
				m_stepOrder = atoi(tok);
				break;
			case 6:
				m_lgKey = atoi(tok);
		}
    }
}
 
/*****************************************************************
 *
 *
 *
 *****************************************************************/
DDefectInfo::~DDefectInfo(  )
{

}

/*****************************************************************
 *
 *
 *
 *****************************************************************/
std::string DDefectInfo::toString()
{	
	std::string outString;
	char buffer1[20], buffer2[20], buffer3[20], buffer4[20], buffer5[20];
	sprintf( buffer1, "%d", m_testNo );
	sprintf( buffer2, "%ld", m_ID );
	sprintf( buffer3, "%d", m_lgKey );
	sprintf( buffer4, "%f", m_size );
	sprintf( buffer5, "%d", m_stepOrder );
	
	outString = m_stepID;
	outString += ";";
	outString += buffer1;
	outString += ";";
	outString += buffer2;
	outString += ";";
	outString += buffer4;
	outString += ";";
	outString += buffer5;
	outString += ";";
	outString += buffer3;  
  
	return outString;
} 


/*****************************************************************
 *
 *
 *
 *****************************************************************/ 
std::ostream& operator<<( std::ostream& os, DDefectInfo& defInfo )
{
	os 	<< defInfo.getStepID() << ";" 
		<< defInfo.getTestNo() << ";" 
		<< defInfo.getID() << ";" 
		<< defInfo.getSize() << ";" 
		<< defInfo.getStepOrder() << ";" 
		<< defInfo.getLgKey() ;
	return os;
}
 